package com.cy.pj.brand.service;

import com.cy.pj.brand.dao.BrandDao;
import com.cy.pj.brand.pojo.Brand;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BrandServiceImpl implements BrandService{
//    private static final Logger log=LoggerFactory.getLogger(BrandServiceImpl.class);
    @Autowired
    private BrandDao brandDao;

    @Override
    public List<Brand> findBrands(String name) {
        log.info("start:{}",System.currentTimeMillis());
        List<Brand> list = brandDao.findBrands(name);
        log.info("end:{}",System.currentTimeMillis());
        return list;
    }

    /**
     * 基于id执行删除
     * @param id
     * @return
     * 思考:将来这个删除业务除了执行数据操作外,还会做什么?
     * 1)权限控制?(有删除权限才能删除)
     * 2)事物控制？
     * 3)日志记录
     */
    @Override
    public int deleteById(Integer id) {
        int rows = brandDao.deleteById(id);
        return rows;
    }

    //添加
    @Override
    public int saveBrand(Brand brand) {
        int rows=brandDao.insertBrand(brand);
        return rows;
    }

    //更新带数据
    @Override
    public Brand findById(Integer id) {
        Brand brand = brandDao.findById(id);
        return brand;
    }

    //更新
    @Override
    public int updateBrand(Brand brand) {
        int rows=brandDao.updateBrand(brand);
        return rows;
    }
}
